package logic_settings_user

import (
	v1 "Sailor/app/Sailor-console-server/api/api_task/v1"
	"Sailor/app/Sailor-console-server/internal/dao"
	"Sailor/app/Sailor-console-server/internal/model/do"
	"context"
	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
)

func (s *sTask) LogicTaskUpdate(ctx context.Context, req *v1.TaskUpdateReq) (res *v1.TaskUpdateRes, err error) {
	_, err = dao.SysTask.Ctx(ctx).Where(dao.SysTask.Columns().Uuid, req.Uuid).Update(do.SysTask{
		Uuid:              req.Uuid,
		TaskName:          req.TaskName,
		TaskGroup:         req.TaskGroup,
		TaskCron:          req.TaskCron,
		TaskInvokeTarget:  req.TaskInvokeTarget,
		TaskArgs:          req.TaskArgs,
		TaskHttpMethod:    req.TaskHttpMethod,
		TaskTimeout:       req.TaskTimeout,
		TaskMulti:         req.TaskMulti,
		TaskRetryTimes:    req.TaskRetryTimes,
		TaskRetryInterval: req.TaskRetryInterval,
		TaskTag:           req.TaskTag,
		TaskRemark:        req.TaskRemark,
		TaskStatus:        req.TaskStatus,
	})
	if err != nil {
		g.Log().Error(ctx, err)
		return nil, gerror.New("修改任务失败")
	}
	return &v1.TaskUpdateRes{}, nil
}
